/*************************************************************************
                           MapGrid  -  description
                             -------------------
    début                : 9 févr. 2012
    copyright            : (C) 2012 par francois
*************************************************************************/

//---------- Réalisation de la classe <MapGrid> (fichier MapGrid.cpp) -------

//---------------------------------------------------------------- INCLUDE

//-------------------------------------------------------- Include système
using namespace std;
#include <iostream>

//------------------------------------------------------ Include personnel
#include "MapGrid.h"

namespace livia {
//------------------------------------------------------------- Constantes

//----------------------------------------------------------------- PUBLIC

//----------------------------------------------------- Méthodes publiques

GridElem& MapGrid :: get(unsigned int x, unsigned int y)
{
#ifdef DEBUG
	if (x >= width || y >= height)
	{
		cerr << "Overflow in MapGrid::get" <<endl;
	}
#endif

	return data[x + y*width];
} //----- Fin de get

void  MapGrid::set(const std::vector<GridView>& modifs)
{
	std::vector<GridView>::const_iterator it;

	for(it = modifs.begin(); it != modifs.end(); ++it)
	{
		data[it->x + (it->y)*width].grid = it->grid;
	}
}

void MapGrid::set(const std::vector<GridCrossable>& modifs)
{
	std::vector<GridCrossable>::const_iterator it;

	for(it = modifs.begin(); it != modifs.end(); ++it)
	{
		data[it->x + (it->y)*width].crossable = it->crossable;
	}

}


//------------------------------------------------- Surcharge d'opérateurs

//-------------------------------------------- Constructeurs - destructeur
MapGrid::MapGrid (unsigned int w, unsigned int h, double scale) :
		width(w), height(h), scale(scale)
{
	data = new GridElem[ w*h ];
	GridElem tofill;
	tofill.crossable = false;
	tofill.grid = NOT_VIEWED;

	fill(data, data + w*h, tofill);
} //----- Fin de MapGrid


MapGrid::~MapGrid ( )
{
	delete[] data;
} //----- Fin de ~MapGrid


//------------------------------------------------------------------ PRIVE

//----------------------------------------------------- Méthodes protégées


}
